package com.xgp.company.创建型模式.第一种_单例模式.利用枚举来实现;

/**
 * 反射不能破坏枚举类型，枚举类纯天然的单例,最简单
 */
public enum SingletonDemo05 {
    INSTANCE;

    public SingletonDemo05 getInstance() {
        return INSTANCE;
    }

    public String hello() {
        return "Hello World!";
    }
}

class SingletonDemo05Test {
    public static void main(String[] args) {
        SingletonDemo05 instance1 = SingletonDemo05.INSTANCE;
        SingletonDemo05 instance2 = SingletonDemo05.INSTANCE.getInstance();

        System.out.println(instance1 == instance2);

        String hello = SingletonDemo05.INSTANCE.hello();
        System.out.println(hello);
    }
}